package com.itheima.demo;

import java.util.Scanner;

//步骤3：设计电影操作类，专门负责电影数据的操作
public class MovieOperator {

    private Movie[] movies;

    public MovieOperator(Movie[] movies) {
        this.movies = movies;
    }

    public void showMovies() {
        System.out.println("========全部电影信息如下========");
        System.out.println("编号\t名称\t价格");
        for (int i = 0; i < movies.length; i++) {
            Movie movie = movies[i];
            System.out.println(movie.getId() + "\t" + movie.getName() + "\t" + movie.getPrice());
        }
    }

    public void showMovieById() {
        System.out.println("========请输入要查询的电影编号========");
        Scanner scanner = new Scanner(System.in);
        int id = scanner.nextInt();
        for (int i = 0; i < movies.length; i++) {
            Movie movie = movies[i];
            if (movie.getId() == id) {
                System.out.println("========查询结果如下========");
                System.out.println("编号\t名称\t价格");
                System.out.println(movie.getId() + "\t" + movie.getName() + "\t" + movie.getPrice());
                return;
            }
        }
        System.out.println("========没有找到该电影========");
    }
}
